#include "bga/graphics/VertexArrayRenderer.h"
#include "bga/graphics/Drawable.h"
#include "bga/graphics/Texture2D.h"
#include <GL/glew.h>

namespace bga
{

VertexArrayRenderer::VertexArrayRenderer() : Renderer()
{

}

VertexArrayRenderer::~VertexArrayRenderer()
{

}

void VertexArrayRenderer::render(const Drawable& drawable) const
{

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    //glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    glVertexPointer(3, GL_FLOAT, 0, drawable.getVertexArray());
    glColorPointer(3, GL_FLOAT, 0, drawable.getColorsArray());

    // TEMP test texture voir remarque dans Drawable.h
    //drawable.getTexture()->bind();

    //glClientActiveTexture(GL_TEXTURE0);
    //glTexCoordPointer(2, GL_FLOAT, 0, drawable.getTexCoordArray());

    glDrawElements(drawable.getPrimitive(), drawable.getIndexArraySize(), GL_UNSIGNED_BYTE, drawable.getIndexArray());

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
}

}
